#!/bin/sh

# 检查是否安装了 zenity
if ! command -v zenity >/dev/null 2>&1; then
    echo "zenity 未安装，请先安装 zenity"
    exit 1
fi

# 如果有命令行参数，直接使用
if [ -n "$1" ]; then
    case $(echo "${1}" | tr '[:lower:]' '[:upper:]') in
        S*) exec curl -L https://gitee.com/songy171/Bazzite-SteamOS-decky-installer/raw/TrainDoctor-patch-1/install_release.sh | sh ;;
        P*) exec curl -L https://github.com/SteamDeckHomebrew/decky-installer/releases/latest/download/install_prerelease.sh | sh ;;
        U*) exec curl -L https://github.com/SteamDeckHomebrew/decky-installer/releases/latest/download/uninstall.sh | sh ;;
    esac
fi

# 显示对话框让用户选择
while true; do
    choice=$(zenity --list \
        --title="Decky 安装器-SteamOS 超人制作" \
        --text="请选择要执行的操作：" \
        --column="选项" --column="描述" \
        "稳定版" "安装稳定版 Decky" \
        "测试版" "安装测试版 Decky" \
        "卸载" "卸载 Decky" \
        --width=300 --height=400 \
        --cancel-label="退出" \
        --ok-label="确定")

    case "$choice" in
        "稳定版")
            zenity --info --title="正在安装" --text="正在安装稳定版..." --width=200 --timeout=2
            exec curl -L https://gitee.com/songy171/Bazzite-SteamOS-decky-installer/raw/TrainDoctor-patch-1/install_release.sh | sh
            ;;
        "测试版")
            zenity --info --title="正在安装" --text="正在安装测试版..." --width=200 --timeout=2
            exec curl -L https://github.com/SteamDeckHomebrew/decky-installer/releases/latest/download/install_prerelease.sh | sh
            ;;
        "卸载")
            if zenity --question --title="确认卸载" --text="确定要卸载 Decky 吗？" --width=200; then
                zenity --info --title="正在卸载" --text="正在卸载 Decky..." --width=200 --timeout=2
                exec curl -L https://github.com/SteamDeckHomebrew/decky-installer/releases/latest/download/uninstall.sh | sh
            fi
            ;;
        *)
            # 用户点击取消或关闭窗口
            exit 0
            ;;
    esac
done
